# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/20 下午5:01
 @Author  : tgy
 
"""


def test01():
    ...
    print(type({1}))

    dic = dict.fromkeys([1, 2, 3], 1)
    print(dic)


def dict_init():
    ...
    d1 = {'1': 2}
    print(d1)
    d2 = dict(name='tony', age=21)
    print(d2)
    d3 = dict.fromkeys([1, 2])
    print(d3)
    d4 = dict([('name', 'maker'), ('age', 21)])
    print(d4)


def dict_get():
    d1 = {'age': 21}
    print(d1['age'])
    # 直接使用下面的方式获取val，如果没有对应的key，则会报 KeyError
    # print(d1['age1'])
    # 使用 get,没有对应的key，返回None
    print(d1.get('age1'))
    # 如果没有对应的val，可以设置默认返回值
    print(d1.get('age1', 1))
    if 'age1' in d1:
        d1.pop('age1')


def dict_zip():
    names = ['tony','mojke']
    ages = [21, 22]
    d1 = dict(zip(names, ages))
    print(d1)


if __name__ == '__main__':
    ...
    # test01()
    # dict_init()
    # dict_get()
    dict_zip()